<template>
	<view>
		<!-- <u-search placeholder="请输入关键字" v-model="keyword"></u-search> -->
		<u-search v-model="keyword" :show-action="false" @change="searchlist" placeholder="请输入关键字"></u-search>
		<u-list @scrolltolower="scrolltolower">
			<u-list-item v-for="(item, index) in buildlist" :key="index">
				<u-cell :title="(index+1)+'、'+item.Name" isLink @click="openpage" :name="item"
					icon="https://cdn.uviewui.com/uview/example/tag.png">
				</u-cell>
			</u-list-item>
			<u-loadmore :status="status" v-if="loading" />
		</u-list>
	</view>
</template>

<script>
	import {
		getbuildlist
	} from '@/common/api.js'
	export default {
		data() {
			return {
				buildlist: [],
				keyword: "",
				pageIndex: 1, //当前页数
				pageSize: 20, //页数大小
				totalPage: "", //总页数
				total: 0, //数据总数
				status: 'loadmore', //加载状态
				loading: true,
				user: JSON.parse(uni.getStorageSync("$userinfo")),
			}
		},
		onLoad() {
			this.getlist()
		},
		methods: {
			openpage(e) {
				uni.navigateTo({
					url: "send?buildid=" + e.name.Id + "&city=" + e.name.City
				})
			},
			async getlist() {
				this.status = 'loading'
				// let querytype = this.$route.query.querytype
				let para = {
					Parameters: [],
				}
				if (this.keyword != "") {
					para.Parameters.push({
						FieldName: "Name",
						ConditionalType: "Like",
						FieldValue: this.keyword
					})

				} else {
					para.Parameters.push({
						FieldName: "Status",
						ConditionalType: "NoEqual",
						FieldValue: "已派工",
					})
				}
				para.Parameters.push({
					FieldName: "Status1st",
					ConditionalType: "NoEqual",
					FieldValue: "结束办理",
				})
				// para.Parameters.push({
				// 	FieldName: "ProjManagerId",
				// 	ConditionalType: "IsNullOrEmpty",
				// 	FieldValue: null,
				// })
				console.log(this.user)
				if (this.user.UserRoleList[0].Role.Name == "项目经理角色" || this.user.UserRoleList[0].Role.Name == "区域经理") {
					para.Parameters.push({
						FieldName: "City",
						ConditionalType: "Equal",
						FieldValue: this.user.Zone,
					})
				} else if (this.user.UserRoleList[0].Role.Name == "管理员角色" || this.user.UserRoleList[0].Role.Name ==
					"公司领导角色") {

				} else
					return;
				para.OrderBys = ['CreateTime desc']
				para.pageSize = this.pageSize
				para.pageIndex = this.pageIndex
				// if (querytype == "日志") {


				// }
				await getbuildlist(para).then(res => {
					let data = res.data
					this.buildlist.push(...data)
					this.total = res.count
					this.totalPage = Math.ceil(this.total / this.pageSize)
				})
			},
			scrolltolower() {
				// 如果当前页数大于等于总页数，状态修改为没有更多了，不再继续往下执行代码
				if (this.pageIndex >= this.totalPage) {
					this.status = 'nomore';
					return;
				};
				this.status = 'loading'; //状态改为加载中
				this.pageIndex = ++this.pageIndex; //页面新增一页
				this.getlist(); //修改页数后，重新获取数据
			},
			async searchlist() {
				this.buildlist = [] //初始化
				this.pageIndex = 1 //初始化当前页数为1
				this.loading = true
				await this.getlist()
				if (this.buildlist.length < this.pageSize) {
					this.loading = false; //如果数据列表小于当前页数，就让加载标签消失
					this.status = 'nomore';
				}else {
					this.status = 'loadmore';
				}
			}
		},
	}
</script>

<style>

</style>